<template>
    <div>
        <h2>会员登录页面</h2>
        <table class="table table-bordered">
            <tr>
                <td>会员真实姓名</td>
                <td>
                    <input type="text" placeholder="请输入真实姓名" v-model="state.name">
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td>
                    <input type="password" placeholder="请输入密码" v-model="state.pwd">
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="登录" @click="login">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { reactive,toRefs } from 'vue';
import { useRouter } from 'vue-router';
const router= useRouter()

const data=reactive({
    state:{
        name: "",
        pwd: "",
    }
})

const {state}=toRefs(data)


//登录
const login = () => {
    if(state.value.name=='')
    {
        alert('会员真实姓名不能为空!');
        return;
    }
    if(state.value.pwd=='')
    {
        alert('会员密码不能为空!');
        return;
    }
    axios({
        url: '/api/High/Login',
        method:'post',
        params:state.value
    })
    .then(res => {
        console.log(res);
        if(res.data.data==-1)
        {
            alert('用户名错误!');
            return;
        }
        else if(res.data.data==-2)
        {
            alert('密码错误!');
            return;
        }
        else if(res.data.data!="")
        {
            alert('登录成功!');
            router.push('/AddMember')
        }
        else{
            alert('登录失败!');
            return;
        }
        
    })
    .catch(err => {
        console.log(err);
    })
}
</script>

<style lang="scss" scoped>

</style>